﻿@model IEnumerable<cyq_dnetmvc.Models.chattable>
@{
    ViewBag.Title = "内页";
}
@section styles{
    <link href="~/Content/themes/cwc/css.min/layer.css?@ViewBag.version" rel="stylesheet" />
}
@functions{
    public static String numberToBgClass(int? number = 6)
    {
        switch (number)
        {
            case 1: return "blackbg"; break;
            case 2: return "slashbg"; break;
            case 3: return "dotbg"; break;
            case 4: return "speedlinebg"; break;
            case 5: return "radiationlinebg"; break;
            case 7: return "gradientbg"; break;
            default: return ""; break;
        }
    }
    public static HtmlString generateDialog(string content, int? dialogtype = 2)
    {
        string htmlstring = "";
        switch (dialogtype)
        {
            case 1:
                {
                    htmlstring += "<div class=\"dialog story\">" + content + "</div>";
                    break;
                }
            case 3:
                {
                    htmlstring += "<div class=\"dialog shout\"><div>" + content + "</div></div>";
                    break;
                }
            case 4:
                {
                    htmlstring += "<div class=\"dialog daze\"><div>" + content + "</div></div>";
                    break;
                }
            case 5:
                {
                    htmlstring += "<div class=\"dialog think\">" + content + "</div>";
                    break;
                }
            default:
                {
                    htmlstring += "<div class=\"dialog say\"><div>" + content + "</div></div>";
                    break;
                }
        }
        return new HtmlString(htmlstring);
    }
}
<div class="cwc-mangapage-wrapper">
    @foreach (var item in Model)
    {
        if (item.chat_celltype == 2)
        {
        <div class="cell twocolumncell">
            <div class="firstspreadcell @numberToBgClass(item.chat_cell1bg)"></div>
            <div class="secondspreadcell @numberToBgClass(item.chat_cell2bg)"></div>
            @generateDialog(item.chat_content, item.chat_dialogtype)
        </div>
        }
        else if (item.chat_celltype == 3)
        { 
        <div class="cell tworowcell">
            <div class="spreadcellwrapper">
                <div class="firstspreadcell">
                    <div class="@numberToBgClass(item.chat_cell1bg)"></div>
                </div>
                <div class="secondspreadcell">
                    <div class="@numberToBgClass(item.chat_cell2bg)"></div>
                </div>
            </div>
            @generateDialog(item.chat_content, item.chat_dialogtype)
        </div>
        }
        else
        { 
        <div class="cell onecell @numberToBgClass(item.chat_cell1bg)">
            @generateDialog(item.chat_content, item.chat_dialogtype)
        </div>
        }
    }
    <div class="cell tworowcell" id="tobec">
        <div class="spreadcellwrapper">
            <div class="firstspreadcell">
                <div class="radiationlinebg"></div>
            </div>
            <div class="secondspreadcell">
                <div class="speedlinebg"></div>
            </div>
        </div>
        <div class="dialog shout">
            <div>
                下面真的没有更多了！——！！！！！真的真的没有更多了！！！！！！
            </div>
        </div>
    </div>
    <input id="chatroomid" value="@ViewBag.chatroomid" type="hidden" />
</div>


@{ Html.RenderPartial("Menu"); }
@section scripts{
    <script>
        //这踏马的还跟顺序有关啊有返回值的在前？按顺序来？
        require(["jqueryv5", "iscroll5", "handlebar4", "text!@Url.Content("~/Content/themes/cwc/html/AddOneCell.html")?@ViewBag.version", "text!@Url.Content("~/Content/themes/cwc/html/generate_onecell.html")?@ViewBag.version", "layer", "commonscripts", "jqvalidate", "@Url.Content("~/Content/themes/cwc/scripts.build/menu_scripts.js")?@ViewBag.version"], function ($, IScroll, Handlebars, addonecelltemp,gonecelltemp, layer, common) {
            console.log(common);
            $(function () {
                //handlebar helper begin
                Handlebars.registerHelper("equal", function (v1, v2, options) {
                    if (v1 == v2) {
                        //满足添加继续执行
                        return options.fn(this);
                    }
                    else {
                        //不满足条件执行{{else}}部分
                        return options.inverse(this);
                    }
                });
                Handlebars.registerHelper("numberToBgClass", function (number) {
                    number = number || 6;
                    switch (number) {
                        case 1: return "blackbg"; break;
                        case 2: return "slashbg"; break;
                        case 3: return "dotbg"; break;
                        case 4: return "speedlinebg"; break;
                        case 5: return "radiationlinebg"; break;
                        case 7: return "gradientbg"; break;
                        default: return ""; break;
                    }
                });
                Handlebars.registerHelper("generateDialog", function (content, dialogtype) {
                    dialogtype = dialogtype || 2;
                    var htmlstring = "";
                    switch (dialogtype) {
                        case 1:
                            {
                                htmlstring += "<div class=\"dialog story\">" + content + "</div>";
                                break;
                            }
                        case 3:
                            {
                                htmlstring += "<div class=\"dialog shout\"><div>" + content + "</div></div>";
                                break;
                            }
                        case 4:
                            {
                                htmlstring += "<div class=\"dialog daze\"><div>" + content + "</div></div>";
                                break;
                            }
                        case 5:
                            {
                                htmlstring += "<div class=\"dialog think\">" + content + "</div>";
                                break;
                            }
                        default:
                            {
                                htmlstring += "<div class=\"dialog say\"><div>" + content + "</div></div>";
                                break;
                            }
                    }
                    return htmlstring;
                });
                //handlebar helper end
                var template = Handlebars.compile(addonecelltemp);
                $.ajax({
                    "url": "@Url.Content("~/Content/themes/cwc/data/dialogtypechooser.json")?@ViewBag.version",
                    "async": false,
                    "dataType": "json",
                    "success": function (data) {
                        console.log(data);
                        var addonecellhtmlstring = template(data);
                        $("body").append(addonecellhtmlstring);
                    }
                });

                $(".cwc-addcellpage .cwc-addcelltextarea > div ul").each(function () {
                    var ulwidth = $(this).find("li").length * 66;
                    $(this).css({"width":ulwidth});
                });
                $(".cwc-addcellpage").css({ "height": $(window).height()});

                var myScroll=[];
                var allchooser = [".cwc-celltypechooser", ".cwc-bg1chooser", ".cwc-bg2chooser", ".cwc-dialogtypechooser"];
                for (var i = 0; i < allchooser.length; i++) {
                    myScroll[i] = new IScroll(allchooser[i], {
                        scrollX: true,
                        scrollY: false,
                        click: true
                    });
                }

                $("body").on("click", ".cwc-chooser li>a", function () {
                    var thischooser = $(this).parents(".cwc-chooser");
                    //$().data 添加和获取和修改 但是修改是独立于dom data-属性的
                    thischooser.data({
                        "dvalue": $(this).data("dvalue")
                    });

                    $(this).parent().siblings().removeClass("active");
                    $(this).parent().addClass("active");
                });
                

                $("body").on("click", ".cwc-addcellpage a.long-btn", function () {
                    if ($.trim($(".cwc-addcelltextarea textarea").val())=="") {
                        layer.open({
                            content: '没输入内容我可就返回了啊',
                            time: 2
                        });
                        closeAddcellpage();
                    }
                    else if ($("#addcellform").valid()) {
                        common.ajax({
                            "url": '@Url.Action("AddOneCell","CwC")',
                            "data": {
                                "topicid": $("#chatroomid").val(),
                                "content": $("[name=dialog_content]").val(),
                                "celltype": $(".cwc-celltypechooser").data("dvalue"),
                                "cellbg1": $(".cwc-bg1chooser").data("dvalue"),
                                "cellbg2": $(".cwc-bg2chooser").data("dvalue"),
                                "dialogtype": $(".cwc-dialogtypechooser").data("dvalue")
                            },
                            "success": function (data) {
                                console.log(data);
                                var template = Handlebars.compile(gonecelltemp);
                                var addonecellhtmlstring = template(data);
                                //console.log(addonecellhtmlstring);
                                $("#tobec").before(addonecellhtmlstring);
                                layer.open({
                                    content: data.msg,
                                    time: 2
                                });
                                closeAddcellpage();
                                $("body").animate({
                                    "scrollTop":$("body").height()
                                });
                            },
                            "type":"POST"
                        });
                    }
                });
                var closeAddcellpage = function () {
                    $("body").css({ "overflow": "auto" });
                    $(".cwc-addcellpage").css({
                        "top": -$(window).height()
                    });
                    $("[name=dialog_content]").val("");
                }
                var validator = $("#addcellform").validate({
                    errorContainer: ".tips .error",
                    errorLabelContainer: $("#addcellform").siblings(".tips").find(".error"),
                    wrapper:"",
                    rules: {
                        dialog_content: {
                            maxlength: 75,
                            required:false
                        }
                    },
                    messages: {
                        dialog_content: {
                            maxlength:"超啦~一个话框吃不了那么多文字的啦~嗝~"
                        }
                    }
                });
            });
        });
    </script>
}



